﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common;
using Whir.Common.WebHelper;

public partial class Whir_System_Main : System.Web.UI.Page
{
    protected string key = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();    //登录判断

        key = Whir.Common.Settings.GetString("AdminCacheKey");
        if (!IsPostBack)
        {
            SetIP();

            InitData();
        }
    }

    private void InitData()
    {
        string sql = "SELECT COUNT(*) FROM Whir_Column";
        object obj = Whir.SQLServerDAL.DbHelperSQL.GetSingle(sql);
        if (obj != null && obj.ToString() == "0")
        {
            //JsHelper.redirect(Page, "网站后台导航为空，请在[栏目管理]中新建栏目", "Module/Role/ColumnList.aspx");
            JsHelper.Alert(Page, "网站后台导航为空，请在[栏目管理]中新建栏目！");
            ClientScript.RegisterStartupScript(this.GetType(), "mes", "RedirectToColumn();", true);
        }
    }

    protected void SetIP()
    {
        string sql = "select count(*) from Whir_AccessStat;";    //PV总

        sql += "select count(*) from Whir_AccessStat where DATEDIFF(DAY,createDate,GETDATE())=0;";    //PV今

        sql += "select count(*) from Whir_AccessStat where DATEDIFF(DAY,createDate,GETDATE())=1;";    //PV昨

        sql += "select count(*) from Whir_AccessStat where DATEDIFF(WEEK,createDate,GETDATE())=0;";    //PV周

        sql += "select count(*) from Whir_AccessStat where DATEDIFF(Month,createDate,GETDATE())=0;";    //PV月

        DataSet ds = Whir.SQLServerDAL.DbHelperSQL.Query(sql);

        this.tdAll.InnerHtml = ds.Tables[0].Rows[0][0].ToString();
        this.tdToday.InnerHtml = ds.Tables[1].Rows[0][0].ToString();
        this.tdYesterday.InnerHtml = ds.Tables[2].Rows[0][0].ToString();
        this.tdWeek.InnerHtml = ds.Tables[3].Rows[0][0].ToString();
        this.tdMonth.InnerHtml = ds.Tables[4].Rows[0][0].ToString();
    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Whir.Log.Model.Whir_OperateLog model = new Whir.Log.Model.Whir_OperateLog();
        model.title = "退出";
        model.operateType = 6;      //退出
        model.operateResult = true;
        model.operateDesc = "退出";

        Whir.Log.OperateLog.Add(model);

        HttpContext.Current.Response.Cookies.Remove(key);

        Response.Redirect("login.aspx"); 
        return;
    }    

    protected string ProductName
    {
        get { return Settings.GetString("ProductName"); }
    }

    protected string ProductVersion
    {
        get { return Settings.GetString("Version"); }
    }

    protected string ProductVersionType
    {
        get { return Settings.GetString("VersionType"); }
    }

    protected string VersionNum
    {
        get { return Settings.GetString("VersionNum"); }
    }
}
